import {defineConfig, loadEnv} from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
    const env = loadEnv(mode, process.cwd()); //获取环境变量
    return {
        plugins: [uni(),],
        resolve: {
            alias: {
                // 设置 `@` 指向 `src` 目录
                "@": path.resolve(__dirname, "./src"),
                "@utils": path.resolve("src/util"),
            },
        },
        // 微信小程序不需要进行跨域转发，需要在ide中配置即可，下面是为了h5开发时进行的跨域
        server: {
            port: 8080,
            hmr: true, //是否热更新
            proxy: {
                [env.VITE_APP_BASE_API]: {
                    target: env.VITE_BUILD_ENV, //转发的后端地址
                    changeOrigin: true,
                }
            }
        }
    };
});
